import Vue from 'vue'
import VueRouter from 'vue-router'
import AdminLogin from '../views/login/AdminLogin'

const index = () =>
    import ('../components/index.vue')
const welcome = () =>
    import ('../components/welcom.vue')
const brief = () =>
    import ('../components/brief/brief.vue')
const comunicate = () =>
    import ('../components/comunicate/comunicate.vue')

const teacher = () =>
    import ('../components/teacher/teacher.vue')
const graduate = () =>
    import ('../components/graduate/gradute.vue')
const college = () =>
    import ('../components/college/college.vue')
const tupian = () =>
    import ('../components/tupian/tupian.vue')
const teacher_detail = () =>
    import ('../components/teacher/Teacher_detail.vue')

const Colleage_detail = () =>
    import ('../components/college/Colleage_detail.vue')
const Comunicate_detail = () =>
    import ('../components/comunicate/Comunicate_detail.vue')
const Technoge = () =>
    import ('../components/Technoge.vue')

const Technoge_detail = () =>
    import ('../components/Technoge_detail.vue')



Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: index,
        redirect: '/welcome',
        children: [{
                path: '/welcome',
                component: welcome
            }, {
                path: '/brief',
                component: brief
            }, {
                path: '/comunicate',
                component: comunicate
            }, {
                path: '/teacher',
                component: teacher
            },
            {
                path: '/graduate',
                component: graduate
            },
            {
                path: '/college',
                component: college
            },
            {
                path: '/Colleage_detail',
                name: '/Colleage_detail',
                component: Colleage_detail
            },
            {
                path: '/Comunicate_detail',
                name: '/Comunicate_detail',
                component: Comunicate_detail
            },
            {
                path: '/Technoge',
                name: '/Technoge',
                component: Technoge
            },
            {
                path: '/Technoge_detail',
                name: '/Technoge_detail',
                component: Technoge_detail
            },


        ]

    },
    {
        path: '/teacher_detail',
        name: '/teacher_detail',
        component: teacher_detail
    },




    //登录
    {
        path: '/views/login',
        name: '/views/login',
        component: AdminLogin,
        // meta: {authRequired: true}
    },
    // 主页面
    {
        path: '/views/main',
        name: '/views/main',
        component: () =>
            import ('@/views/Main.vue'),
        //师资队伍
        children: [
            // 首页
            {
                path: '/main/indextotal',
                name: '/main/indextotal',
                component: () =>
                    import ('@/views/IndexTotal.vue'),
                meta: {
                    breadList: ["数据统计"],
                    authRequired: true
                }
            },
            //师资队伍  列表
            {
                path: '/main/facultylist',
                name: '/main/facultylist',
                component: () =>
                    import ('@/views/teacher/FacultyList.vue'),
                meta: {
                    breadList: ["师资队伍", "教师列表"],
                    authRequired: true
                }
            },
            // 添加教师
            {
                path: '/main/addfaculty',
                name: '/main/addfaculty',
                component: () =>
                    import ('@/views/teacher/AddTea.vue'),
                meta: {
                    breadList: ["师资队伍", "添加教师"],
                    authRequired: true
                }
            },
            //文章管理
            {
                path: '/main/artical',
                name: '/main/artical',
                component: () =>
                    import ('@/views/Artical/ArticleList.vue'),
                meta: {
                    breadList: ["文章管理", "文章列表"],
                    authRequired: true
                }
            },
            {
                path: '/main/articalpost',
                name: '/main/articalpost',
                component: () =>
                    import ('@/views/Artical/PostArticle.vue'),
                meta: {
                    breadList: ["文章管理", "发表文章"],
                    authRequired: true
                }
            },
            // 编辑文章
            {
                path: '/main/articaledit',
                name: '/main/articaledit',
                component: () =>
                    import ('@/views/Artical/EditBlog.vue'),
                // meta: { breadList: ["文章管理","编辑文章"] }
                meta: { authRequired: true }
            },

            // 用户添加
            {
                path: '/main/users',
                name: '/main/users',
                component: () =>
                    import ('@/views/users/AddUsers.vue'),
                meta: {
                    breadList: ["用户管理", "添加用户"],
                    authRequired: true
                }
            },
            //用户列表
            {
                path: '/main/userlist',
                name: '/main/userlist',
                component: () =>
                    import ('@/views/users/UserList.vue'),
                meta: {
                    breadList: ["用户管理", "用户列表"],
                    authRequired: true
                }
            },
            //轮播图
            {
                path: '/main/homelist',
                name: '/main/homelist',
                component: () =>
                    import ('@/views/homeImg/HomeImg.vue'),
                meta: {
                    breadList: ["轮播图"],
                    authRequired: true
                }
            },
            //日志管理
            {
                path: '/main/log',
                name: '/main/log',
                component: () =>
                    import ('@/views/Log.vue'),
                meta: {
                    breadList: ["日志管理"],
                    authRequired: true
                }
            }
        ]
    },
    {
        path: '/*',
        redirect: '/home'

    },
]

const router = new VueRouter({
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    //   console.log(to)
    // 判断是否需要登录拦截
    if (to.meta.authRequired) {
        if (sessionStorage.getItem('username')) {

            next()
        } else {
            // next({path: '/views/login'})
            // next({path: '/views/login', query:{redirect: to.fullPath}})
            return next('/views/login')
        }
    } else {
        next()
    }
})

export default router